package com.glory.good_dark.activity;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.viewpager.widget.PagerAdapter;

import com.glory.good_dark.R;
import com.glory.good_dark.application.BaseActivity;
import com.glory.good_dark.customview.HackyViewPager;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import uk.co.senab.photoview.PhotoView;

/**
 * FileName: ShowBigPictureActivity
 * Author: XJH
 * Date: 2020/7/29 9:42
 * Description:
 * History:图片预览
 */
public class ShowBigPictureActivity extends BaseActivity {
    @BindView(R.id.view_pager)
    HackyViewPager mViewPager;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    private int position;
    private static ArrayList<String> mList;
    private static int type;//0表示网址，1表示本地图片

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_big_picture;
    }

    @Override
    protected void initView() {
        position = getIntent().getIntExtra("position", 0);
        type = getIntent().getIntExtra("type", 0);
        mList = getIntent().getStringArrayListExtra("data");
        if (mList == null) {
            return;
        }
        mViewPager.setAdapter(new SamplePagerAdapter());
        mViewPager.setCurrentItem(position);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return null;
    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    static class SamplePagerAdapter extends PagerAdapter {


        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            if (type == 0) {
                photoView.setImageResource(R.drawable.img_add_ablum);
            } else {
                photoView.setImageURI(Uri.parse(mList.get(position)));
            }
            // Now just add PhotoView to ViewPager and return it
            container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

    }

}
